package com.qf.controller;

import com.qf.pojo.MyInfo;
import com.qf.service.MyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;
import java.util.Map;

@RestController("/myinfo")
public class MyInfoController {
    @Autowired
    MyInfoService myInfoService;
    @RequestMapping("/findMyInfoAll")
    public List<MyInfo> findAll(){
        return myInfoService.findAll();
    }

    @RequestMapping("/findMyInfoById")
    public MyInfo findById(@RequestBody Map map){
        Integer mid=(Integer)map.get("id");
        return myInfoService.findById(mid);
    }

    @RequestMapping("/deleteByMid")
    public void delete(@RequestBody Map map){
        Integer mid=(Integer)map.get("id");
        myInfoService.delete(mid);
    }

    @RequestMapping("/addAndUpdateMyInfo")
    public String addAndUpdate(MyInfo myInfo){
        MyInfo myInfo1 = myInfoService.addAndUpdate(myInfo);
        if(myInfo1!=null){
            return "success";
        }else{
            return "fail";
        }
    }


    @RequestMapping("/findByMat")
    public List<MyInfo> findByMat(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        return myInfoService.findByMat(id);
    }


    @RequestMapping("/findByMem")
    public List<MyInfo> findByMem(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        return myInfoService.findByMem(id);
    }@RequestMapping("/findByMco")
    public List<MyInfo> findByMco(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        return myInfoService.findByMco(id);
    }@RequestMapping("/findByMno")
    public List<MyInfo> findByMno(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        return myInfoService.findByMno(id);
    }
    //用户根据字段属性删除相关消息
    @RequestMapping("/deleteByMat")
    public void deleteByMat(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        myInfoService.deleteByMat(id);
    }

    @RequestMapping("/deleteByMem")
    public void deleteByMem(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        myInfoService.deleteByMem(id);
    }
    @RequestMapping("/deleteByMco")
    public void deleteByMco(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        myInfoService.deleteByMco(id);
    }
    @RequestMapping("/deleteByMno")
    public void deleteByMno(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        myInfoService.deleteByMno(id);
    }
}
